<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>意达设计</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css"/>
    <link rel="stylesheet" type="text/css" href="../css/dealer.css"/>

</head>
<body class="body">

<!-- header -->
<div class="pageheader"><a href="javascript:void(0);" onclick="api.closeWin();" class="return"></a><span>申请退单</span></div>

<!-- content -->
<div class="detailderlie">
	<div class="derli">
		<div class="der_n1"><span  id='orderno'>订单号：2018091117361529</span> <em>已收货</em></div>
		<div class="der_n2">
			<div class="derimg"><img src="../image/page/img-026.jpg" id='icon'></div>
			<div class="deright">
				<a href="#" id='name'>稻草人女包包2018新款复古手提包</a>
				<div class="derone"><span id='color'>颜色：红色、黄色、紫色</span> <em id='price'>￥15</em></div>
				<div class="dertwo"><span id='num'>数量： X10</span> <em style="display: none">￥2199起</em></div>
			</div>
		</div>
		<div class="der_n3">
			<p>总计：¥<span id='money'>150.00</span></p>
		</div>
	</div>
</div>

<div class="pad">
	<div class="retudes"><textarea placeholder="申请退货理由" id='reason' style="padding-top: 0.05rem"></textarea></div>
	<div class="retdelist">
		<ul id='imgcon'>
			
            
		</ul>
        <input type="hidden" id='iconid' name='icon' value="">
		<div class="licimg"><img src="../image/dealer/img-006.jpg"  onclick="showAction()"></div>
	</div>
    <div class="logBnt"><input type="button" value="提交申请" onclick="backorder()"></div>
</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/adaptive.js"></script>
<script type="text/javascript" src="../script/swiper.min.js"></script>
<script type="text/javascript" src="../script/tabs.js"></script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

    apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        });
        api.showProgress();

        var para=api.pageParam;
    

    	var p={token:token,id:para.id};

        toDoRequest(p);

    };

  	function toDoRequest(p){
		api.ajax({
            url: webSiteUrl+'/app/user/orderdetail',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
                
                //alert(ret.msg);return;
              
                var tj=ret.data;
                $('#icon').attr('src',webSiteUrl+tj.icon);
                $('#price').html(tj.price);
    			$('#money').html(tj.money);
    			
    			$('#name').html(tj.name);
    			$('#orderno').html('订单号：'+tj.orderno);
    			$('#color').html('颜色：'+tj.color);
    			$('#num').html('数量：'+tj.num);

                		
            }else{
                //alert(ret.msg)
            }

		});
	}
	function backorder(){
	  	var para=api.pageParam
	  	var reason=$('#reason').val();
        var icon=$("input[name=icon]").val();
   		var p={token:token,id:para.id,reason:reason,icon:icon};
   		api.ajax({
            url: webSiteUrl+'/app/user/backorder',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
            	alert(ret.msg);
                api.openWin({
                    name: 'shopName',
                    url: './myorder.html',
                    reload: true,
                    pageParam: {
                        type: 1,
                    }
                });
            }else{
            	alert(ret.msg)
            }
        })
   	}

function showAction() {
    var len=$('#imgcon').children().length;
    if(len==6){
        alert("最多上传6张图片");return;
    }
    api.actionSheet({
         title: '上传图片',
         cancelTitle: '取消',
         buttons: ['拍照', '从手机相册选择']
    }, function(ret, err) {
         if (ret) {
             getPicture(ret.buttonIndex);
         }
    });
}
function getPicture(sourceType) {
        if (sourceType == 1) { // 拍照
            //获取一张图片
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'png',
                mediaValue: 'pic',
                allowEdit: false,
                quality: 90,
                saveToPhotoAlbum: true
            }, function(ret, err) {
                // 获取拍照数据并处理
                if (ret) {

                    var imgSrc = ret.data;
                    if (imgSrc != "") {
                        
                        //$api.attr(ele, 'src', imgSrc);
                    }
                    if (ret.hasOwnProperty("list")) {
                        
                        //var localAvaterPath = ret.data;
                        //$api.attr(ele, 'src', ret.list[0].path);
                        api.showProgress({
                            title: '正在上传...',
                            modal: true
                        });
                    }
                    var ele = $api.dom('#icon1');
                    api.ajax({
                        url: webSiteUrl+'/app/public/uploads',
                        method: 'post',
                        data: {
                            files: {
                                'file': ret.data,
                            }
                        }
                    }, function(ret, err) {
                        if(ret.data==''){return;}
                        if (ret) {
                            if (ret.code == 200) {
                                //alert(JSON.stringify(ret));
                                api.hideProgress();
                                
                                //$api.attr(ele, 'src', webSiteUrl+ret.pic);
                                
                                
                                
                                addpic(ret.id,ret.pic);
                               

                            } else {
                                api.hideProgress();
                                api.toast({
                                    msg: ret.msg,
                                    location: 'middle'
                                });
                            }
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: err.msg,
                                location: 'middle'
                            });
                        }
                    });




                }
            });
        } else if (sourceType == 2) { // 从相机中选择
            //UIMediaScanner 是一个多媒体扫描器，可扫描系统的图片、视频等多媒体资源
            var obj = api.require('UIMediaScanner');
            obj.open({
                //返回的资源种类,picture（图片）,video（视频）,all（图片和视频）
                type: 'picture',
                //（可选项）图片显示的列数，须大于1
                column: 4,
                max: 1,
                //（可选项）图片排序方式,asc（旧->新）,desc（新->旧）
                sort: {
                    key: 'time',
                    order: 'desc'
                },
                //（可选项）模块各部分的文字内容
                texts: {
                    stateText: '已选择*项',
                    cancelText: '取消',
                    finishText: '完成'
                },
                styles: {
                    bg: '#fff',
                    mark: {
                        icon: '',
                        position: 'bottom_right',
                        size: 20
                    },
                    nav: {
                        bg: '#eee',
                        stateColor: '#000',
                        stateSize: 18,
                        cancleBg: 'rgba(0,0,0,0)',
                        cancelColor: '#000',
                        cancelSize: 18,
                        finishBg: 'rgba(0,0,0,0)',
                        finishColor: '#000',
                        finishSize: 18
                    }
                }
            }, function(ret) {
                if(ret.eventType=='cancel'){return;}
                if (ret) {
                    if (ret.hasOwnProperty("list")) {
                        
                        //var localAvaterPath = ret.list[0].path;
                        //$api.attr(ele, 'src', ret.list[0].path);
                        api.showProgress({
                            title: '正在上传...',
                            modal: true
                        });
                    }
                    var ele = $api.dom('#icon1');
                    api.ajax({
                        url: webSiteUrl+'/app/public/uploads',
                        method: 'post',
                        data: {
                            files: {
                                'file': ret.list[0].path,
                            }
                        }
                    }, function(ret, err) {
                        if (ret) {
                            if (ret.code == 200) {
                                //alert(JSON.stringify(ret));
                                api.hideProgress();
                                
                                //$api.attr(ele, 'src', webSiteUrl+ret.pic);
                                
                                addpic(ret.id,ret.pic);

                            } else {
                                api.hideProgress();
                                api.toast({
                                    msg: ret.msg,
                                    location: 'middle'
                                });
                            }
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: err.msg,
                                location: 'middle'
                            });
                        }
                    });





                }
            });
        }
    }

   function addpic(id,imgpath){
    
    var ids=$("#iconid").val();

    
    if(ids != ''){
        ids+=','+id;
    }else{
        ids=id;
    }
    $("#iconid").val(ids);

    var a='<li><img src="'+webSiteUrl+imgpath+'"/></li>';

    $("#imgcon").append(a);

}
</script>

</html>
